<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>定位居中</title>
    <style>
        body{
            margin: 0;
        }
        .c1{
            background-color: yellow;
            width: 600px;
            height: 600px;
            margin: auto;
            margin-top: 100px;
            position: relative;
        }
        .c2{
            width: 200px;
            height: 200px;
            background-color:red;
            position: absolute;
              margin-top: 50%;
              margin-left: 50%;
            transform: translate(-50%,-50%);


        }
    </style>
</head>

<body>
    <div class="c1">

        <div class="c2">

        </div>
    </div>

</body>
</html>